package leetcode.D200.T104;

import util.TreeNode;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: DYZ
 * @Create: 2021-08-20 10:15:55 星期五
 */

public class Solution {
    /**
     * 解法1：BFS
     * @param root
     * @return
     */
    /*public int maxDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        Deque<TreeNode> dq = new LinkedList<>();
        dq.addLast(root);
        int depth = 0;
        while (!dq.isEmpty()) {
            depth++;
            int size = dq.size();
            for(int i=0; i<size; ++i) {
                TreeNode front = dq.removeFirst();
                if(front.left != null) {
                    dq.addLast(front.left);
                }
                if(front.right != null) {
                    dq.addLast(front.right);
                }
            }
        }
        return depth;
    }*/

    /**
     * 解法2：DFS
     * @param root
     * @return
     */
    /*public int maxDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
    }*/

    // 二刷
    public int maxDepth(TreeNode root) {
        if (root == null)
            return 0;
        return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }
}
